<?php

namespace app\models;

use Yii;
use yii\behaviors\TimestampBehavior;

/**
 * This is the model class for table "{{%product}}".
 *
 * @property integer $id
 * @property string $title
 * @property integer $cid
 * @property integer $user_id
 * @property integer $cover
 * @property string $pics
 * @property string $description
 * @property integer $created_at
 * @property integer $updated_at
 * @property integer $sort
 * @property integer $views
 * @property integer $num
 * @property string $price
 * @property string $content
 * @property integer $is_hot
 * @property integer $is_tui
 * @property string $sale_price
 * @property integer $is_on
 * @property integer $status
 */
class Product extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%product}}';
    }

    public function behaviors()
    {
        return [
            TimestampBehavior::className()
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['title', 'pics', 'description', 'price', 'content', 'sale_price'], 'required'],
            [['cid', 'user_id', 'cover', 'created_at', 'updated_at', 'sort', 'views', 'num', 'is_hot', 'is_tui', 'is_on', 'status'], 'integer'],
            [['price', 'sale_price'], 'number'],
            [['content'], 'string'],
            [['title'], 'string', 'max' => 80],
            [['pics'], 'string', 'max' => 20],
            [['description'], 'string', 'max' => 128],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'title' => '产品标题',
            'cid' => '所属类别',
            'user_id' => '用户',
            'cover' => '封面图',
            'pics' => '产品图集',
            'description' => '简介',
            'created_at' => '添加时间',
            'updated_at' => '更新时间',
            'sort' => '排序',
            'views' => '浏览次数',
            'num' => '库存',
            'price' => '市场价',
            'content' => '详细介绍',
            'is_hot' => '热门',
            'is_tui' => '推荐',
            'sale_price' => '销售价',
            'is_on' => 'Is On',
            'status' => '状态',
        ];
    }

    public function getCate(){
        return $this->hasOne(ProductCate::className(), ['id'=>'cid']);
    }
}
